package mmoon.mmoonstory.items.armors;

import mmoon.mmoonstory.MMoonUtils;
import mmoon.mmoonstory.interfaces.InitItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class ArmorObsidianChestPlate extends ItemArmor implements InitItem {
    public static final String ObjID = "obsidian_chestplate";

    public ArmorObsidianChestPlate() {
        super(MMoonUtils.OBSIDIAN_A, 1, EntityEquipmentSlot.CHEST);
        this.init(ObjID);
    }

    @Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
        if (!world.isRemote) {
            ArmorObsidianChestPlate.appEffect(player, MobEffects.SLOWNESS, 3, 1);
        }
    }

    public static void appEffect(EntityPlayer player, Potion effect, int amplifier, int second) {
        if (player.getActivePotionEffect(effect) == null
                || player.getActivePotionEffect(effect).getDuration() < second * 20
                || player.getActivePotionEffect(effect).getAmplifier() < amplifier) {
            player.addPotionEffect(new PotionEffect(effect, second * 20, amplifier, false, true));
        }
    }
}
